package com.bh.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bh.common.annotation.DataDictClass;
import com.bh.common.constant.Entity;
import com.bh.common.utils.DateUtils;
import com.bh.common.utils.SecurityUtils;
import com.bh.order.domain.JcZoneStoreroom;
import com.bh.order.mapper.JcZoneStoreroomMapper;
import com.bh.order.service.IJcZoneStoreroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 库房分区Service业务层处理
 *
 * @author slx
 * @date 2023-04-24
 */
@Service
public class JcZoneStoreroomServiceImpl extends ServiceImpl<JcZoneStoreroomMapper, JcZoneStoreroom> implements IJcZoneStoreroomService {
    @Autowired
    private JcZoneStoreroomMapper jcZoneStoreroomMapper;

    /**
     * 查询库房分区
     *
     * @param id 库房分区主键
     * @return 库房分区
     */
    @DataDictClass
    @Override
    public JcZoneStoreroom selectJcZoneStoreroomById(Long id) {
        return jcZoneStoreroomMapper.selectById(id);
    }

    /**
     * 查询库房分区列表
     *
     * @param jcZoneStoreroom 库房分区
     * @return 库房分区
     */
    @DataDictClass
    @Override
    public List<JcZoneStoreroom> selectJcZoneStoreroomList(JcZoneStoreroom jcZoneStoreroom) {
        return jcZoneStoreroomMapper.selectJcZoneStoreroomList(jcZoneStoreroom);
    }

    @Override
    public List<JcZoneStoreroom> selectJcZoneStoreroomMap() {
        JcZoneStoreroom jcZoneStoreroom = new JcZoneStoreroom();
        jcZoneStoreroom.setStatus(Entity.ACTIVE);
        jcZoneStoreroom.setJcOrganizationId(SecurityUtils.getOrgId());
        return jcZoneStoreroomMapper.selectJcZoneStoreroomList(jcZoneStoreroom);
    }

    /**
     * 新增库房分区
     *
     * @param jcZoneStoreroom 库房分区
     * @return 结果
     */
    @Override
    public int insertJcZoneStoreroom(JcZoneStoreroom jcZoneStoreroom) {
        jcZoneStoreroom.setCreateTime(DateUtils.getNowDate());
        jcZoneStoreroom.setCreateName(SecurityUtils.getUsername());
        return jcZoneStoreroomMapper.insert(jcZoneStoreroom);
    }

    /**
     * 修改库房分区
     *
     * @param jcZoneStoreroom 库房分区
     * @return 结果
     */
    @Override
    public int updateJcZoneStoreroom(JcZoneStoreroom jcZoneStoreroom) {
        jcZoneStoreroom.setModifyTime(DateUtils.getNowDate());
        jcZoneStoreroom.setModifyName(SecurityUtils.getUsername());
        return jcZoneStoreroomMapper.updateById(jcZoneStoreroom);
    }

    /**
     * 批量删除库房分区
     *
     * @param ids 需要删除的库房分区主键
     * @return 结果
     */
    @Override
    public int deleteJcZoneStoreroomByIds(Long[] ids) {
        return jcZoneStoreroomMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除库房分区信息
     *
     * @param id 库房分区主键
     * @return 结果
     */
    @Override
    public int deleteJcZoneStoreroomById(Long id) {
        return jcZoneStoreroomMapper.deleteById(id);
    }
}
